<template>
  <div class="app-container">
    <el-row :gutter="10">
      <!--试验数据设置-->
      <el-col :span="4" :xs="24">
        <div class="app-container-tree-border">
          <el-input v-model="syTypeName" placeholder="请输入试验依据" clearable size="small" prefix-icon="el-icon-search" />
          <el-tree class="input-tree" :data="options" :props="defaultProps" :expand-on-click-node="false" :filter-node-method="filterNode" ref="tree" node-key="id" default-expand-all highlight-current @node-click="handleNodeClick">
            <div slot-scope="{node, data}" class="custom-tree-node" :title="node.label" v-text="node.label"></div>
          </el-tree>
        </div>
      </el-col>
      <!--试验明细数据-->
      <el-col :span="20" :xs="24">
        <div class="app-container-table-border">
          <!--       leaf2-->
          <div v-if="twoShow">
            <el-row :gutter="10" class="mb8 top-right-btn sycs-add">
              <el-col :span="1.5">
                <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAddleaf2()">新增</el-button>
              </el-col>
            </el-row>
            <el-table border stripe v-loading="loading" :data="dataBaseList">
              <el-table-column label="序号" align="center" type="index" width="80" />
              <el-table-column label="名称" align="center" prop="syYjName" min-width="140" :show-overflow-tooltip="true" />
              <el-table-column label="操作" align="center" fixed="right" width="140" :show-overflow-tooltip="true">
                <template slot-scope="scope" v-if="twoShow">
                  <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdateleaf2(scope.row)">修改</el-button>
                  <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDeleteleaf2(scope.row)">删除</el-button>
                </template>
              </el-table-column>
            </el-table>

            <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />
          </div>
          <!--        leaf3-->
          <div v-if="threeShow">
            <el-row :gutter="10" class="mb8 top-right-btn sycs-add">
              <el-col :span="1.5">
                <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAddleaf3()">新增</el-button>
              </el-col>
            </el-row>
            <el-table border stripe v-loading="loading" :data="dataBaseList">
              <el-table-column label="序号" align="center" type="index" width="80" />
              <el-table-column label="名称" align="center" prop="syYjName" min-width="140" :show-overflow-tooltip="true" />
              <el-table-column label="备注" align="center" prop="remark" min-width="140" :show-overflow-tooltip="true" />
              <el-table-column label="操作" align="center" fixed="right" width="140">
                <template slot-scope="scope" v-if="threeShow">
                  <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdateleaf3(scope.row)">修改</el-button>
                  <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDeleteleaf2(scope.row)">删除</el-button>
                </template>
              </el-table-column>
            </el-table>

            <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />
          </div>
          <!--        detailWater-->
          <div v-if="fourShow">
            <el-row :gutter="10" class="mb8 top-right-btn sycs-add">
              <el-col :span="1.5">
                <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAddDetailWater">新增</el-button>
              </el-col>
            </el-row>
            <el-table border stripe v-loading="loading" :data="dataBaseList">
              <el-table-column label="序号" align="center" type="index" width="80" />
              <el-table-column label="试验温度（℃）" align="center" prop="temp" min-width="140" :show-overflow-tooltip="true" />
              <el-table-column label="水的密度（g/cm³）" align="center" prop="density" min-width="140" :show-overflow-tooltip="true" />
              <el-table-column label="水温修正系数" align="center" prop="coefficient" min-width="140" :show-overflow-tooltip="true" />
              <el-table-column label="操作" align="center" fixed="right" width="140">
                <template slot-scope="scope" v-if="fourShow">
                  <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdateDetailWater(scope.row)">修改</el-button>
                  <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDeleteDetailWater(scope.row)">删除</el-button>
                </template>
              </el-table-column>
            </el-table>

            <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />
          </div>
          <!--        detailSy-->
          <div v-if="fiveShow">
            <el-row :gutter="10" class="mb8 top-right-btn sycs-add">
              <el-col :span="1.5">
                <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAddDetailSy">新增</el-button>
              </el-col>
            </el-row>
            <el-table border stripe v-loading="loading" :data="dataBaseList">
              <el-table-column label="序号" align="center" type="index" width="80" />
              <el-table-column label="温度（℃）" align="center" prop="temp" min-width="140" :show-overflow-tooltip="true" />
              <el-table-column label="空气黏度（µPa·s）" align="center" prop="viscosity" min-width="140" :show-overflow-tooltip="true" />
              <el-table-column label="操作" align="center" fixed="right" width="140">
                <template slot-scope="scope" v-if="fiveShow">
                  <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdateDetailSy(scope.row)">修改</el-button>
                  <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDeleteDetailSy(scope.row)">删除</el-button>
                </template>
              </el-table-column>
            </el-table>

            <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />
          </div>
          <!--        detail-->
          <div v-if="sixShow">
            <el-row :gutter="10" class="mb8 top-right-btn sycs-add">
              <el-col :span="1.5">
                <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAddDetail">新增</el-button>
              </el-col>
            </el-row>
            <el-table border stripe v-loading="loading" :data="dataBaseList">
              <el-table-column label="序号" align="center" type="index" width="80" />
              <el-table-column label="尺寸" align="center" prop="size" min-width="140" :show-overflow-tooltip="true" />
              <el-table-column label="上限" align="center" prop="maxVal" min-width="140" :show-overflow-tooltip="true" />
              <el-table-column label="下限" align="center" prop="minVal" min-width="140" :show-overflow-tooltip="true" />
              <el-table-column label="操作" align="center" fixed="right" width="140">
                <template slot-scope="scope" v-if="sixShow">
                  <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdateDetail(scope.row)">修改</el-button>
                  <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDeleteDetail(scope.row)">删除</el-button>
                </template>
              </el-table-column>
            </el-table>

            <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />
          </div>

          <!--        detailGj-->
          <div v-if="sevenShow">
            <el-row :gutter="10" class="mb8 top-right-btn sycs-add">
              <el-col :span="1.5">
                <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAddDetailGj">新增</el-button>
              </el-col>
            </el-row>
            <el-table border stripe v-loading="loading" :data="dataBaseList">
              <el-table-column label="序号" align="center" type="index" width="80" />
              <el-table-column label="公称直径mm" align="center" prop="diameter" min-width="140" :show-overflow-tooltip="true" />
              <el-table-column label="公称横截面面积mm²" align="center" prop="area" min-width="140" :show-overflow-tooltip="true" />
              <el-table-column label="理论重量kg/m" align="center" prop="weight" min-width="140" :show-overflow-tooltip="true" />
              <el-table-column label="操作" align="center" fixed="right" width="140">
                <template slot-scope="scope" v-if="sevenShow">
                  <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdateDetailGj(scope.row)">修改</el-button>
                  <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDeleteDetailGj(scope.row)">删除</el-button>
                </template>
              </el-table-column>
            </el-table>

            <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />
          </div>
        </div>
      </el-col>
    </el-row>

    <!-- 添加或修改试验数据设置主表对话框 -->
    <jy-dialog :title="title" :visible.sync="openLeaf2" width="600px" append-to-body>
      <el-form ref="formLeaf2" :model="formLeaf2" :rules="rulesLeaf2" label-width="120px">
        <el-form-item label="所属试验依据">
          <div style="font-weight: bolder; font-size: 16px;">{{ formLeaf2.parentName }}</div>
        </el-form-item>
        <el-form-item label="名称" prop="syYjName">
          <el-input v-model="formLeaf2.syYjName" placeholder="请输入名称" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="formLeaf2.remark" placeholder="请输入备注" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="small" :loading="buttonLoadingLeaf2" type="primary" @click="submitForm(1)">确 定</el-button>
        <el-button size="small" @click="cancel">取 消</el-button>
      </div>
    </jy-dialog>

    <jy-dialog :title="title" :visible.sync="openLeaf3" width="600px" append-to-body>
      <el-form ref="formLeaf3" :model="formLeaf3" :rules="rulesLeaf3" label-width="120px">
        <el-form-item label="所属试验依据">
          <div style="font-weight: bolder; font-size: 16px;">{{ formLeaf3.parentName }}</div>
        </el-form-item>
        <el-form-item label="名称" prop="syYjName">
          <el-input v-model="formLeaf3.syYjName" placeholder="请输入名称" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="formLeaf3.remark" placeholder="请输入备注" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="small" :loading="buttonLoadingLeaf3" type="primary" @click="submitForm(2)">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </jy-dialog>

    <jy-dialog :title="title" :visible.sync="openDetailWater" width="600px" append-to-body>
      <el-form ref="formDetailWater" :model="formDetailWater" :rules="rulesDetailWater" label-width="150px">
        <el-form-item label="所属试验依据">
          <div style="font-weight: bolder; font-size: 16px;">{{ formDetailWater.parentName }}</div>
        </el-form-item>
        <el-form-item label="试验温度（℃）" prop="temp">
          <el-input type="number" v-model="formDetailWater.temp" placeholder="请输入试验温度" />
        </el-form-item>
        <el-form-item label="水的密度（g/cm³）" prop="density">
          <el-input type="number" v-model="formDetailWater.density" placeholder="请输入水的密度" />
        </el-form-item>
        <el-form-item label="水温修正系数" prop="coefficient">
          <el-input type="number" v-model="formDetailWater.coefficient" placeholder="请输入水温修正系数" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="small" :loading="buttonLoadingDetailWater" type="primary" @click="submitForm(3)">确 定</el-button>
        <el-button size="small" @click="cancel">取 消</el-button>
      </div>
    </jy-dialog>

    <jy-dialog :title="title" :visible.sync="openDetailSy" width="600px" append-to-body>
      <el-form ref="formDetailSy" :model="formDetailSy" :rules="rulesDetailSy" label-width="150px">
        <el-form-item label="所属试验依据">
          <div style="font-weight: bolder; font-size: 16px;">{{ formDetailSy.parentName }}</div>
        </el-form-item>
        <el-form-item label="温度（℃）" prop="temp">
          <el-input type="number" v-model="formDetailSy.temp" placeholder="请输入温度" />
        </el-form-item>
        <el-form-item label="空气黏度（µPa·s）" prop="viscosity">
          <el-input type="number" v-model="formDetailSy.viscosity" placeholder="请输入空气黏度" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="small" :loading="buttonLoadingDetailSy" type="primary" @click="submitForm(4)">确 定</el-button>
        <el-button size="small" @click="cancel">取 消</el-button>
      </div>
    </jy-dialog>

    <jy-dialog :title="title" :visible.sync="openDetail" width="600px" append-to-body>
      <el-form ref="formDetail" :model="formDetail" :rules="rulesDetail" label-width="150px">
        <el-form-item label="所属试验依据">
          <div style="font-weight: bolder; font-size: 16px;">{{ formDetail.parentName }}</div>
        </el-form-item>
        <el-form-item label="尺寸" prop="size">
          <el-input type="number" v-model="formDetail.size" placeholder="请输入尺寸" />
        </el-form-item>
        <el-form-item label="上限" prop="maxVal">
          <el-input type="number" v-model="formDetail.maxVal" placeholder="请输入上限" />
        </el-form-item>
        <el-form-item label="下限" prop="maxVal">
          <el-input type="number" v-model="formDetail.minVal" placeholder="请输入下限" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="small" :loading="buttonLoadingDetail" type="primary" @click="submitForm(5)">确 定</el-button>
        <el-button size="small" @click="cancel">取 消</el-button>
      </div>
    </jy-dialog>

    <jy-dialog :title="title" :visible.sync="openDetailGj" width="600px" append-to-body>
      <el-form ref="formDetailGj" :model="formDetailGj" :rules="rulesDetailGj" label-width="150px">
        <el-form-item label="所属试验依据">
          <div style="font-weight: bolder; font-size: 16px;">{{ formDetailGj.parentName }}</div>
        </el-form-item>
        <el-form-item label="公称直径mm" prop="diameter">
          <el-input v-model="formDetailGj.diameter" placeholder="请输入公称直径" />
        </el-form-item>
        <el-form-item label="公称横截面面积mm²" prop="area">
          <el-input v-model="formDetailGj.area" placeholder="请输入公称横截面面积" />
        </el-form-item>
        <el-form-item label="理论重量kg/m" prop="weight">
          <el-input v-model="formDetailGj.weight" placeholder="请输入理论重量" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="small" :loading="buttonLoadingDetailGj" type="primary" @click="submitForm(6)">确 定</el-button>
        <el-button size="small" @click="cancel">取 消</el-button>
      </div>
    </jy-dialog>
  </div>
</template>

<script>
import {
  listDataBase,
  getDataBase,
  delDataBase,
  addDataBase,
  updateDataBase,
  syTpyeTree,
  listBySyTypeId,
  handleDeleteLeaf2,
  handleDeleteDetailWater,
  handleDeleteDetailSy,
  handleDeleteDetail,
  updateSyYj,
  addSyYj,
  updateDetailWater,
  addDetailWater,
  addDetailSy,
  updateDetailSy,
  addDetail,
  updateDetail,
  getSyYj,
  getDetailWater,
  getDetailSy,
  getDetail,
  getDetailGj,
  updateDetailGj,
  addDetailGj,
  handleDeleteDetailGj
} from "@/api/sycs/dataBase";
import { deptTreeSelect } from "@/api/system/user";

export default {
  name: "DataBase",
  dicts: ["sy_data_project"],
  data() {
    return {
      // 按钮loading
      buttonLoading: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 试验数据设置主表表格数据
      dataBaseList: [],
      // 弹出层标题
      title: "新增",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        syYjId: undefined
      },
      // 当前树节点
      currentNode: {},
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
      syTypeName: undefined,
      options: [],
      defaultProps: {
        children: "children",
        label: "label"
      },
      twoShow: false, // leaf2
      threeShow: false, // leaf3
      fourShow: false, // detailWater
      fiveShow: false, // detailSy
      sixShow: false, // detail
      sevenShow: false, // detailGj

      formLeaf2: {},
      formLeaf3: {},
      formDetailWater: {},
      formDetailSy: {},
      formDetailGj: {},
      formDetail: {},

      rulesLeaf2: {
        syYjName: [{ required: true, message: "名称不能为空", trigger: ["blur"] }]
      },
      rulesLeaf3: {
        syYjName: [{ required: true, message: "名称不能为空", trigger: ["blur"] }]
      },
      rulesDetailWater: {
        temp: [{ required: true, message: "试验温度不能为空", trigger: ["blur"] }],
        density: [{ required: true, message: "水的密度不能为空", trigger: ["blur"] }],
        coefficient: [{ required: true, message: "水温修正系数不能为空", trigger: ["blur"] }]
      },
      rulesDetailSy: {
        temp: [{ required: true, message: "温度不能为空", trigger: ["blur"] }],
        viscosity: [{ required: true, message: "空气黏度不能为空", trigger: ["blur"] }]
      },
      rulesDetail: {
        size: [{ required: true, message: "尺寸不能为空", trigger: ["blur"] }],
        maxVal: [{ required: true, message: "上限不能为空", trigger: ["blur"] }],
        minVal: [{ required: true, message: "下限不能为空", trigger: ["blur"] }]
      },
      rulesDetailGj: {
        diameter: [{ required: true, message: "公称直径不能为空", trigger: ["blur"] }],
        area: [{ required: true, message: "公称横截面面积不能为空", trigger: ["blur"] }],
        weight: [{ required: true, message: "理论重量不能为空", trigger: ["blur"] }]
      },

      openLeaf2: false,
      openLeaf3: false,
      openDetailWater: false,
      openDetailSy: false,
      openDetail: false,
      openDetailGj: false,

      buttonLoadingLeaf2: false,
      buttonLoadingLeaf3: false,
      buttonLoadingDetailWater: false,
      buttonLoadingDetailSy: false,
      buttonLoadingDetail: false,
      buttonLoadingDetailGj: false,
    };
  },
  created() {
    // this.getList();
    this.getDeptTree();
  },
  watch: {
    // 根据名称筛选树
    syTypeName(val) {
      this.$refs.tree.filter(val);
    }
  },
  methods: {
    /** 查询试验数据设置主表列表 */
    getList() {
      this.loading = true;
      listBySyTypeId(this.queryParams).then((response) => {
        const data = response.data;
        if (data.type == "detailWater") {
          this.fourShow = true;
          this.twoShow = false;
          this.threeShow = false;
          this.fiveShow = false;
          this.sixShow = false;
          this.sevenShow = false;
        } else if (data.type == "detailSy") {
          this.fiveShow = true;
          this.twoShow = false;
          this.threeShow = false;
          this.fourShow = false;
          this.sixShow = false;
          this.sevenShow = false;
        } else if (data.type == "detailGj") {
          this.sevenShow = true;
          this.twoShow = false;
          this.threeShow = false;
          this.fourShow = false;
          this.fiveShow = false;
          this.sixShow = false;
        } else if (data.type == "leaf2") {
          this.twoShow = true;
          this.threeShow = false;
          this.fourShow = false;
          this.fiveShow = false;
          this.sixShow = false;
          this.sevenShow = false;
        } else if (data.type == "leaf3") {
          this.threeShow = true;
          this.twoShow = false;
          this.fourShow = false;
          this.fiveShow = false;
          this.sixShow = false;
          this.sevenShow = false;
        } else {
          this.sixShow = true;
          this.threeShow = false;
          this.twoShow = false;
          this.fourShow = false;
          this.fiveShow = false;
          this.sevenShow = false;
        }
        this.dataBaseList = response.data.page.records;
        this.total = response.data.page.total;
        this.loading = false;
      });
    },
    /** 查询组织下拉树结构 */
    getDeptTree() {
      syTpyeTree().then((response) => {
        this.options = response.data;
      });
    },
    // 取消按钮
    cancel() {
      this.openLeaf2 = false;
      this.openLeaf3 = false;
      this.openDetailWater = false;
      this.openDetailSy = false;
      this.openDetailGj = false;
      this.openDetail = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.formLeaf2 = {
        delFlag: undefined,
        createBy: undefined,
        createTime: undefined,
        updateBy: undefined,
        updateTime: undefined
      };
      this.formLeaf3 = {
        delFlag: undefined,
        createBy: undefined,
        createTime: undefined,
        updateBy: undefined,
        updateTime: undefined
      };
      this.formDetailWater = {
        delFlag: undefined,
        createBy: undefined,
        createTime: undefined,
        updateBy: undefined,
        updateTime: undefined
      };
      this.formDetailSy = {
        delFlag: undefined,
        createBy: undefined,
        createTime: undefined,
        updateBy: undefined,
        updateTime: undefined
      };
      this.formDetailGj = {
        delFlag: undefined,
        createBy: undefined,
        createTime: undefined,
        updateBy: undefined,
        updateTime: undefined
      };
      this.formDetail = {
        delFlag: undefined,
        createBy: undefined,
        createTime: undefined,
        updateBy: undefined,
        updateTime: undefined
      };
      this.resetForm("formLeaf2");
      this.resetForm("formLeaf3");
      this.resetForm("formDetailWater");
      this.resetForm("formDetailSy");
      this.resetForm("formDetailGj");
      this.resetForm("formDetail");
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
    },
    handleAddleaf2() {
      this.reset();
      this.openLeaf2 = true;
      this.openDetailWater = false;
      this.openDetailSy = false;
      this.openDetailGj = false;
      this.openDetail = false;
      this.$set(this.formLeaf2, "parentId", this.currentNode.id);
      this.$set(this.formLeaf2, "parentName", this.currentNode.label);
      this.title = "新增";
    },
    handleAddleaf3() {
      this.reset();
      this.openLeaf3 = true;
      this.openLeaf2 = false;
      this.openDetailWater = false;
      this.openDetailSy = false;
      this.openDetailGj = false;
      this.openDetail = false;
      this.$set(this.formLeaf3, "parentId", this.currentNode.id);
      this.$set(this.formLeaf3, "parentName", this.currentNode.label);
      this.title = "新增";
    },
    handleAddDetailWater() {
      this.reset();
      this.openLeaf2 = false;
      this.openDetailWater = true;
      this.openDetailSy = false;
      this.openDetailGj = false;
      this.openDetail = false;
      this.$set(this.formDetailWater, "syTypeId", this.currentNode.id);
      this.$set(this.formDetailWater, "parentName", this.currentNode.label);
      this.title = "新增";
    },
    handleAddDetailSy() {
      this.reset();
      this.openLeaf2 = false;
      this.openDetailWater = false;
      this.openDetailSy = true;
      this.openDetailGj = false;
      this.openDetail = false;
      this.$set(this.formDetailSy, "syTypeId", this.currentNode.id);
      this.$set(this.formDetailSy, "parentName", this.currentNode.label);
      this.title = "新增";
    },
    handleAddDetailGj() {
      this.reset();
      this.openLeaf2 = false;
      this.openDetailWater = false;
      this.openDetailSy = false;
      this.openDetailGj = true;
      this.openDetail = false;
      this.$set(this.formDetailGj, "syTypeId", this.currentNode.id);
      this.$set(this.formDetailGj, "parentName", this.currentNode.label);
      this.title = "新增";
    },
    handleAddDetail() {
      this.reset();
      this.openLeaf2 = false;
      this.openDetailWater = false;
      this.openDetailSy = false;
      this.openDetailGj = false;
      this.openDetail = true;
      this.$set(this.formDetail, "syTypeId", this.currentNode.id);
      this.$set(this.formDetail, "parentName", this.currentNode.label);
      this.title = "新增";
    },
    handleUpdateleaf2(row) {
      this.loading = true;
      this.reset();
      const syYjId = row.syYjId;
      getSyYj(syYjId).then((response) => {
        this.loading = false;
        this.formLeaf2 = response.data;
        this.$set(this.formLeaf2, "parentId", this.currentNode.id);
        this.$set(this.formLeaf2, "parentName", this.currentNode.label);
        this.openLeaf2 = true;
        this.openLeaf3 = false;
        this.openDetailWater = false;
        this.openDetailSy = false;
        this.openDetailGj = false;
        this.openDetail = false;
        this.title = "修改";
      });
    },
    handleUpdateleaf3(row) {
      this.loading = true;
      this.reset();
      const syYjId = row.syYjId;
      getSyYj(syYjId).then((response) => {
        this.loading = false;
        this.formLeaf3 = response.data;
        this.$set(this.formLeaf3, "parentId", this.currentNode.id);
        this.$set(this.formLeaf3, "parentName", this.currentNode.label);
        this.openLeaf3 = true;
        this.openLeaf2 = false;
        this.openDetailWater = false;
        this.openDetailSy = false;
        this.openDetailGj = false;
        this.openDetail = false;
        this.title = "修改";
      });
    },
    handleUpdateDetailWater(row) {
      this.loading = true;
      this.reset();
      const deId = row.deId;
      getDetailWater(deId).then((response) => {
        this.loading = false;
        this.formDetailWater = response.data;
        this.$set(this.formDetailWater, "syTypeId", this.currentNode.id);
        this.$set(this.formDetailWater, "parentName", this.currentNode.label);
        this.openDetailWater = true;
        this.openLeaf2 = false;
        this.openLeaf3 = false;
        this.openDetailSy = false;
        this.openDetailGj = false;
        this.openDetail = false;
        this.title = "修改";
      });
    },
    handleUpdateDetailSy(row) {
      this.loading = true;
      this.reset();
      const deId = row.deId;
      getDetailSy(deId).then((response) => {
        this.loading = false;
        this.formDetailSy = response.data;
        this.$set(this.formDetailSy, "syTypeId", this.currentNode.id);
        this.$set(this.formDetailSy, "parentName", this.currentNode.label);
        this.openDetailSy = true;
        this.openDetailGj = false;
        this.openLeaf2 = false;
        this.openLeaf3 = false;
        this.openDetailWater = false;
        this.openDetail = false;
        this.title = "修改";
      });
    },
    handleUpdateDetailGj(row) {
      this.loading = true;
      this.reset();
      const deId = row.deId;
      getDetailGj(deId).then((response) => {
        this.loading = false;
        this.formDetailGj = response.data;
        this.$set(this.formDetailGj, "syTypeId", this.currentNode.id);
        this.$set(this.formDetailGj, "parentName", this.currentNode.label);
        this.openDetailGj = true;
        this.openDetailSy = false;
        this.openLeaf2 = false;
        this.openLeaf3 = false;
        this.openDetailWater = false;
        this.openDetail = false;
        this.title = "修改";
      });
    },
    handleUpdateDetail(row) {
      this.loading = true;
      this.reset();
      const deId = row.deId;
      getDetail(deId).then((response) => {
        this.loading = false;
        this.formDetail = response.data;
        this.$set(this.formDetail, "syTypeId", this.currentNode.id);
        this.$set(this.formDetail, "parentName", this.currentNode.label);
        this.openDetail = true;
        this.openLeaf2 = false;
        this.openLeaf3 = false;
        this.openDetailWater = false;
        this.openDetailSy = false;
        this.openDetailGj = false;
        this.title = "修改";
      });
    },
    /** 提交按钮 */
    submitForm(flag) {
      if (flag == 1) {
        this.$refs["formLeaf2"].validate((valid) => {
          if (valid) {
            this.buttonLoadingLeaf2 = true;
            if (this.formLeaf2.syYjId != null) {
              updateSyYj(this.formLeaf2)
                .then((response) => {
                  this.$modal.msgSuccess("修改成功");
                  this.openLeaf2 = false;
                  this.getList();
                  this.getDeptTree();
                })
                .finally(() => {
                  this.buttonLoadingLeaf2 = false;
                });
            } else {
              addSyYj(this.formLeaf2)
                .then((response) => {
                  this.$modal.msgSuccess("新增成功");
                  this.openLeaf2 = false;
                  this.getList();
                  this.getDeptTree();
                })
                .finally(() => {
                  this.buttonLoadingLeaf2 = false;
                });
            }
          }
        });
      }
      if (flag == 2) {
        this.$refs["formLeaf3"].validate((valid) => {
          if (valid) {
            this.buttonLoadingLeaf3 = true;
            if (this.formLeaf3.syYjId != null) {
              updateSyYj(this.formLeaf3)
                .then((response) => {
                  this.$modal.msgSuccess("修改成功");
                  this.openLeaf3 = false;
                  this.getList();
                  this.getDeptTree();
                })
                .finally(() => {
                  this.buttonLoadingLeaf3 = false;
                });
            } else {
              this.$set(this.formLeaf3, "yjDetailType", "DETAIL");
              addSyYj(this.formLeaf3)
                .then((response) => {
                  this.$modal.msgSuccess("新增成功");
                  this.openLeaf3 = false;
                  this.getList();
                  this.getDeptTree();
                })
                .finally(() => {
                  this.buttonLoadingLeaf3 = false;
                });
            }
          }
        });
      }
      if (flag == 3) {
        this.$refs["formDetailWater"].validate((valid) => {
          if (valid) {
            this.buttonLoadingDetailWater = true;
            if (this.formDetailWater.deId != null) {
              updateDetailWater(this.formDetailWater)
                .then((response) => {
                  this.$modal.msgSuccess("修改成功");
                  this.openDetailWater = false;
                  this.getList();
                  this.getDeptTree();
                })
                .finally(() => {
                  this.buttonLoadingDetailWater = false;
                });
            } else {
              addDetailWater(this.formDetailWater)
                .then((response) => {
                  this.$modal.msgSuccess("新增成功");
                  this.openDetailWater = false;
                  this.getList();
                  this.getDeptTree();
                })
                .finally(() => {
                  this.buttonLoadingDetailWater = false;
                });
            }
          }
        });
      }
      if (flag == 4) {
        this.$refs["formDetailSy"].validate((valid) => {
          if (valid) {
            this.buttonLoadingDetailSy = true;
            if (this.formDetailSy.deId != null) {
              updateDetailSy(this.formDetailSy)
                .then((response) => {
                  this.$modal.msgSuccess("修改成功");
                  this.openDetailSy = false;
                  this.getList();
                  this.getDeptTree();
                })
                .finally(() => {
                  this.buttonLoadingDetailSy = false;
                });
            } else {
              addDetailSy(this.formDetailSy)
                .then((response) => {
                  this.$modal.msgSuccess("新增成功");
                  this.openDetailSy = false;
                  this.getList();
                  this.getDeptTree();
                })
                .finally(() => {
                  this.buttonLoadingDetailSy = false;
                });
            }
          }
        });
      }
      if (flag == 5) {
        this.$refs["formDetail"].validate((valid) => {
          if (valid) {
            this.buttonLoadingDetail = true;
            if (this.formDetail.deId != null) {
              updateDetail(this.formDetail)
                .then((response) => {
                  this.$modal.msgSuccess("修改成功");
                  this.openDetail = false;
                  this.getList();
                  this.getDeptTree();
                })
                .finally(() => {
                  this.buttonLoadingDetail = false;
                });
            } else {
              addDetail(this.formDetail)
                .then((response) => {
                  this.$modal.msgSuccess("新增成功");
                  this.openDetail = false;
                  this.getList();
                  this.getDeptTree();
                })
                .finally(() => {
                  this.buttonLoadingDetail = false;
                });
            }
          }
        });
      }
      if (flag == 6) {
        this.$refs["formDetailGj"].validate((valid) => {
          if (valid) {
            this.buttonLoadingDetailGj = true;
            if (this.formDetailGj.deId != null) {
              updateDetailGj(this.formDetailGj)
                .then((response) => {
                  this.$modal.msgSuccess("修改成功");
                  this.openDetailGj = false;
                  this.getList();
                  this.getDeptTree();
                })
                .finally(() => {
                  this.buttonLoadingDetailGj = false;
                });
            } else {
              addDetailGj(this.formDetailGj)
                .then((response) => {
                  this.$modal.msgSuccess("新增成功");
                  this.openDetailGj = false;
                  this.getList();
                  this.getDeptTree();
                })
                .finally(() => {
                  this.buttonLoadingDetailGj = false;
                });
            }
          }
        });
      }
    },
    handleDeleteleaf2(row) {
      const syYjId = row.syYjId;
      this.$modal
        .confirm("确认删除？")
        .then(() => {
          this.loading = true;
          return handleDeleteLeaf2(syYjId);
        })
        .then(() => {
          this.loading = false;
          this.getList();
          this.getDeptTree();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {})
        .finally(() => {
          this.loading = false;
        });
    },
    handleDeleteDetailWater(row) {
      const deId = row.deId;
      this.$modal
        .confirm("确认删除？")
        .then(() => {
          this.loading = true;
          return handleDeleteDetailWater(deId);
        })
        .then(() => {
          this.loading = false;
          this.getList();
          this.getDeptTree();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {})
        .finally(() => {
          this.loading = false;
        });
    },
    handleDeleteDetailSy(row) {
      const deId = row.deId;
      this.$modal
        .confirm("确认删除？")
        .then(() => {
          this.loading = true;
          return handleDeleteDetailSy(deId);
        })
        .then(() => {
          this.loading = false;
          this.getList();
          this.getDeptTree();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {})
        .finally(() => {
          this.loading = false;
        });
    },
    handleDeleteDetailGj(row) {
      const deId = row.deId;
      this.$modal
        .confirm("确认删除？")
        .then(() => {
          this.loading = true;
          return handleDeleteDetailGj(deId);
        })
        .then(() => {
          this.loading = false;
          this.getList();
          this.getDeptTree();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {})
        .finally(() => {
          this.loading = false;
        });
    },
    handleDeleteDetail(row) {
      const deId = row.deId;
      this.$modal
        .confirm("确认删除？")
        .then(() => {
          this.loading = true;
          return handleDeleteDetail(deId);
        })
        .then(() => {
          this.loading = false;
          this.getList();
          this.getDeptTree();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {})
        .finally(() => {
          this.loading = false;
        });
    },
    // 筛选节点
    filterNode(value, data) {
      if (!value) return true;
      return data.label.indexOf(value) !== -1;
    },
    // 节点单击事件
    handleNodeClick(data) {
      this.queryParams.syYjId = data.id;
      this.$set(this.currentNode, "id", data.id);
      this.$set(this.currentNode, "label", data.label);
      this.getList();
    }
  }
};
</script>
<style lang="scss" scoped>
  @import "~@/assets/styles/demo.scss";
</style>
